import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { TableSkill } from "../../../common/table/TableSkill";
import { SkillCls } from "../bll/content/SkillCastingCls";
import { SkillCastingNormal } from "../bll/content/SkillCastingNormal";
import { SkillAnimatorCls } from "../view/content/SkillAnimatorCls";
import { SkillAnimator } from "../view/content/SkillAnimator";
import { SkillCasting } from "../bll/content/SkillCasting";
import { EffectDamage } from "./report/EffectDamage";

/** 技能数据 */
@ecs.register('SkillModel')
export class SkillModelComp extends ecs.Comp {
    /** 技能编号 */
    get id(): number {
        return this.table.id;
    }
    set id(value: number) {
        if (this.table == null) this.table = new TableSkill();
        this.table.init(value);
        this.attackType = this.table.attack_type;
        this.skillRatio = this.table.attack_ratio;

        // 技能逻辑
        var cls = SkillCls[value];
        if (cls) {
            this.casting = new cls();
        }
        else {
            this.casting = new SkillCastingNormal();
        }

        // 技能动画
        var cls = SkillAnimatorCls[value];
        if (cls)
            this.animator = new cls();
        else
            this.animator = new SkillAnimator();
    }
      /** 静态表中一条数据 */
      table: TableSkill = null!;

       /** 技能施放 */
    casting: SkillCasting = null!;
    /** 技能战报播放 */
    animator: SkillAnimator = null!;
    /** 攻击类型
     *  1:  默认攻击
        2:  前排
        3:  后排
        4:  随机3个
        5:  全体
        6:  攻击力最高
        7:  攻击力最低
        8:  生命最高
        9:  生命最低
        10: 随机1个
     */
    attackType: number = 1;
    /** 技能伤害百分比 */
    skillRatio: number = 1;
    /** 是否已经学习该技能 */
    learned: number = 0;
    effectDamage: EffectDamage = null!;

    /** 技能受击特效 */
    get effectHitPath(): string{
        if(this.table.effect_hit){
            var roleNickName = this.casting.caster.RoleModel.table.nickName;
            if(this.table.id < 1000 || this.table.id > 20000){
                return `content/enemy/${roleNickName}/${this.table.effect_hit}`;
            }else{
                return `content/role/${roleNickName}/${this.table.effect_hit}`;
            }
        }
        else{
            return "content/effect/gongjian_attack_hit";
        }
    }

    /** 技能弹道特效 */
    get effectBallisticPath(): string | null{
        if(this.table.effect_ballistic){
            var roleNickName = this.casting.caster.RoleModel.table.nickName;
            if(this.table.id < 1000 || this.table.id > 20000){
                return `content/enemy/${roleNickName}/${this.table.effect_ballistic}`;
            }else{
                return `content/role/${roleNickName}/${this.table.effect_ballistic}`;
            }
        }
        else{
            return null;
        }
    }

    reset(): void {
        this.casting = null!;
        this.animator = null!;
    }
}